//
//  VCOfUser.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/24.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "VCOfUser.h"
#import "Masonry.h"
#import "NetWorkingHandle.h"
#import "ModelOfUser.h"
#import "ImageTextModle.h"
#import "UIImageView+WebCache.h"
@interface VCOfUser ()
@property(nonatomic, retain)NSMutableArray *arrOfData;

@property(nonatomic, retain)UIImageView *imageOfBackbround;

@property(nonatomic, retain)UILabel *lableOfHeader;

@property(nonatomic, retain)UILabel *lableOfMid;

@property(nonatomic, retain)UIImageView *imageOfTool;

@property(nonatomic, retain)UILabel *lableOfFooter;

@property(nonatomic, retain)UIImageView *imageOfUserPic;

@property(nonatomic, retain)UILabel *lableOfUserName;

@property(nonatomic, retain)UILabel *labelOfInteraction;

@property(nonatomic, retain)NSMutableDictionary *mDic;
@end

@implementation VCOfUser



- (void)dealloc{
    [_imageOfBackbround release];
    [_lableOfHeader release];
    [_lableOfMid release];
    [_imageOfTool release];
    [_lableOfFooter release];
    [_imageOfUserPic release];
    [_lableOfUserName release];
    [_labelOfInteraction release];
    [_strOfhand_id release];
    
    [super dealloc];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor greenColor];
    [self getData];
    [self creat];
//    [self getData];
    
}

#pragma mark - 布置子控件
- (void)creat{
    
    
    self.imageOfBackbround = [[UIImageView alloc]init];
    
//    self.imageOfBackbround.backgroundColor = [UIColor grayColor];
    
    [self.view addSubview:self.imageOfBackbround];
    
    [self.imageOfBackbround mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.centerY.equalTo(self.view.mas_centerY);
        make.width.offset(SCREEN_WIDTH);
        make.height.offset(SCREEN_HEIGHT + 40);
    }];
    
    self.lableOfHeader = [[UILabel alloc]init];
    
//    self.lableOfHeader.backgroundColor = [UIColor yellowColor];
    [self.imageOfBackbround addSubview:self.lableOfHeader];
    [self.lableOfHeader mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageOfBackbround.mas_top).offset(SCREEN_HEIGHT / 5);
        make.leading.equalTo(self.imageOfBackbround.mas_leading).offset(40);
        make.width.offset(SCREEN_WIDTH - 80);
        make.height.offset(40);
        
    }];
    self.lableOfHeader.font = [UIFont systemFontOfSize:21];
    
    self.lableOfHeader.textAlignment = NSTextAlignmentCenter;
    self.lableOfHeader.textColor = [UIColor whiteColor];

    UIView *lineOfTop = [[UIView alloc]init];
    lineOfTop.backgroundColor = [UIColor colorWithRed:246.0 / 256.0f green:246.0 / 256.0f blue:246.0 / 256.0f alpha:0.3];
    
    
    [self.imageOfBackbround addSubview:lineOfTop];
    
    [lineOfTop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lableOfHeader.mas_bottom).offset(40);
        make.leading.equalTo(self.imageOfBackbround.mas_leading).offset(25);
        make.width.offset(SCREEN_WIDTH - 50);
        make.height.offset(0.5);
        
    }];
//
    self.lableOfMid = [[UILabel alloc]init];
    
//    self.lableOfMid.backgroundColor = [UIColor yellowColor];
    
    [self.imageOfBackbround addSubview:self.lableOfMid];
    
    [self.lableOfMid mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineOfTop.mas_bottom).offset(7);
        make.centerX.equalTo(lineOfTop.mas_centerX);
        make.width.equalTo(lineOfTop.mas_width);
    }];
    
    self.lableOfMid.textColor = [UIColor whiteColor];
    self.lableOfMid.numberOfLines = 0;
    self.lableOfMid.font = [UIFont systemFontOfSize:13];
//
    UIView *lineOfbelow = [[UILabel alloc]init];
    
    lineOfbelow.backgroundColor = [UIColor colorWithRed:246.0 / 256.0f green:246.0 / 256.0f blue:246.0 / 256.0f alpha:0.3];
    
    [self.imageOfBackbround addSubview:lineOfbelow];
    
    [lineOfbelow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(lineOfTop.mas_centerX);
        make.width.equalTo(lineOfTop.mas_width);
        make.height.equalTo(lineOfTop.mas_height);
        make.top.equalTo(self.lableOfMid.mas_bottom).offset(7);
    }];
//
    self.imageOfTool = [[UIImageView alloc]init];
//    self.imageOfTool.backgroundColor = [UIColor redColor];
    [self.imageOfBackbround addSubview:self.imageOfTool];
    
    [self.imageOfTool mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(lineOfbelow.mas_bottom).offset(3);
        make.leading.equalTo(self.imageOfBackbround.mas_leading).offset(25);
        make.height.offset(20);
        make.width.offset(20);
        
    }];
//
    self.lableOfFooter = [[UILabel alloc]init];
//    self.lableOfFooter.backgroundColor = [UIColor yellowColor];
    [self.imageOfBackbround addSubview:self.lableOfFooter];
    
    [self.lableOfFooter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.imageOfTool.mas_centerY);
        make.height.equalTo(self.imageOfTool.mas_height);
        make.leading.equalTo(self.imageOfTool.mas_trailing).offset(3);
        make.width.offset(100);
    }];
    self.lableOfFooter.font = [UIFont systemFontOfSize:11];
    self.lableOfFooter.textColor = [UIColor grayColor];
    
    self.imageOfUserPic = [[UIImageView alloc]init];
    
//    self.imageOfUserPic.backgroundColor = [UIColor redColor];
    [self.imageOfBackbround addSubview:self.imageOfUserPic];

    [self.imageOfUserPic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.lableOfMid.mas_centerX);
        make.bottom.equalTo(self.imageOfBackbround.mas_bottom).offset( - SCREEN_HEIGHT / 4);
        make.height.offset(60);
        make.width.offset(60);
        
        
    }];
    
    self.imageOfUserPic.layer.cornerRadius = 30;
    self.imageOfUserPic.layer.masksToBounds = YES;
    
    
    
    self.lableOfUserName = [[UILabel alloc]init];
    
//    self.lableOfUserName.backgroundColor = [UIColor yellowColor];
    self.lableOfUserName.font = [UIFont systemFontOfSize:23];
    [self.imageOfBackbround addSubview:self.lableOfUserName];
    
    [self.lableOfUserName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageOfUserPic.mas_bottom).offset(5);
        make.centerX.equalTo(self.imageOfUserPic.mas_centerX);
        make.width.offset(SCREEN_WIDTH - 20);
        make.height.offset(30);
        
        
    }];
    self.lableOfUserName.textAlignment = NSTextAlignmentCenter;
    self.lableOfUserName.textColor = [UIColor whiteColor];
    
    
    self.labelOfInteraction = [[UILabel alloc]init];
    
//    self.labelOfInteraction.backgroundColor = [UIColor yellowColor];
    
    [self.imageOfBackbround addSubview:self.labelOfInteraction];
    [self.labelOfInteraction mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.imageOfUserPic.mas_centerX);
        make.top.equalTo(self.lableOfUserName.mas_bottom).offset(25);
        make.width.equalTo(self.lableOfUserName.mas_width);
        make.height.offset(15);
    }];
    
    self.labelOfInteraction.textAlignment = NSTextAlignmentCenter;
    self.labelOfInteraction.textColor = [UIColor whiteColor];
    self.labelOfInteraction.font = [UIFont systemFontOfSize:13];
    UIButton *buttonOfBack = [UIButton buttonWithType:UIButtonTypeSystem];
//    buttonOfBack.backgroundColor = [UIColor greenColor];
    [self.view addSubview:buttonOfBack];
    
    [buttonOfBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.imageOfBackbround.mas_centerX);
        make.bottom.equalTo(self.view.mas_bottom).offset( - 15);
        make.height.offset(30);
        make.width.offset(30);
        
        [buttonOfBack setImage:[UIImage imageNamed:@"20.png"] forState:UIControlStateNormal];
        [buttonOfBack addTarget:self action:@selector(GetBack:) forControlEvents:UIControlEventTouchUpInside];
        [buttonOfBack setTintColor:[UIColor whiteColor]];
        
    }];

    
    
    
    
    
    [_imageOfBackbround release];
    [_lableOfHeader release];
    [lineOfTop release];
    [_lableOfMid release];
    [lineOfbelow release];
    [_imageOfTool release];
    [_lableOfFooter release];
    [_imageOfUserPic release];
    [_lableOfUserName release];
    [_labelOfInteraction release];
    
    
    
    
    
    
    
    
    
    
}


#pragma mark - 返回
- (void)GetBack:(UIButton *)back{
    
    
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
    
    
}


#pragma mark - 获取数据
- (void)getData{
    
    NetWorkingHandle *net = [[NetWorkingHandle alloc]init];
    
//    ImageTextModle *model = [[ImageTextModle alloc]init];
//    self.strOfhand_id = model.hand_id;
    NSString *url = [NSString stringWithFormat: @"http://m.shougongke.com/index.php?&c=Course&a=CourseDetial&id=%@&vid=18", self.strOfhand_id];
    
    NSLog(@"%@", url);
    
//    self.arrOfData = [NSMutableArray array];
    
    [net netWorkingHandlerGetWithURL:url completion:^(id result, NSData *data, NSURLResponse *response, NSError *error)
    {
       
        self.mDic = [result objectForKey:@"data"];
        
        NSLog(@"%@", self.mDic);
        
        
        
        [self.imageOfBackbround sd_setImageWithURL:[NSURL URLWithString:[self.mDic objectForKey:@"host_pic_m"]] placeholderImage:nil];
        self.lableOfHeader.text = [self.mDic objectForKey:@"subject"];
        self.lableOfMid.text = [self.mDic objectForKey:@"summary"];
        [self.imageOfTool sd_setImageWithURL:[NSURL URLWithString:[self.mDic objectForKey:@"cate_pic"]] placeholderImage:nil];
        self.lableOfFooter.text = [self.mDic objectForKey:@"cate_name"];
        [self.imageOfUserPic sd_setImageWithURL:[NSURL URLWithString:[self.mDic objectForKey:@"face_pic"]] placeholderImage:nil];
        self.lableOfUserName.text = [self.mDic objectForKey:@"user_name"];
        
        NSString *str1 = @"人气  |  ";
        
        NSString *str2 = @"收藏  |  ";
        
        NSString *str3 = @"评论  |  ";
        
        NSString *str4 = @"  赞";
        self.labelOfInteraction.text =[[[[[[[[self.mDic objectForKey:@"view"] stringByAppendingString:str1]stringByAppendingString:self.mDic[@"collect"]]stringByAppendingString:str2]stringByAppendingString:self.mDic[@"comment_num"]]stringByAppendingString:str3]stringByAppendingString:self.mDic[@"laud"]]stringByAppendingString:str4];
        
        
    }];
    
    
    
    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
